[PM-34009] chore: Create KeychainServiceFacade#2507
[PM-34009] chore: Create KeychainServiceFacade#2507KatherineInCode wants to merge 45 commits intomainfrom
Conversation
|
Great job! No new security vulnerabilities introduced in this pull request |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2507 +/- ##
==========================================
- Coverage 87.07% 85.99% -1.09%
==========================================
Files 1859 2086 +227
Lines 164172 178692 +14520
==========================================
+ Hits 142955 153668 +10713
- Misses 21217 25024 +3807 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| extension MockKeychainItem: Equatable { | ||
| public convenience init(unformattedKey: String) { | ||
| public convenience init( | ||
| unformattedKey: String, |
There was a problem hiding this comment.
Not alphabetized to put optional parameters at the end
| } | ||
|
|
||
| public func getValue(for item: any KeychainItem) async throws -> String { | ||
| let foundItem = try await keychainService.search( |
There was a problem hiding this comment.
While this could have gone in the guard, I feel like this is a little easier to read.
Bitwarden Claude Code ReviewOverall Assessment: APPROVE This PR consolidates keychain interaction logic from three separate implementations ( Code Review DetailsNo findings identified. The refactoring is clean and well-tested.
|
matt-livefront
left a comment
There was a problem hiding this comment.
This is great, nice job!
|
|
||
| // MARK: AuthenticatorKey | ||
|
|
||
| public func deleteAuthenticatorKey() async throws { |
There was a problem hiding this comment.
⛏️ Looks like this was like this before, but should this be documented? Or should the other methods not be documented since they are documented by the protocol?
| try await subject.setAccountAutoLogoutTime(date, userId: "1") | ||
|
|
||
| XCTAssertTrue(keychainServiceFacade.setValueCalled) | ||
| XCTAssertEqual( | ||
| keychainServiceFacade.setValueReceivedArguments?.item.unformattedKey, | ||
| SharedKeychainItem.accountAutoLogout(userId: "1").unformattedKey, |
There was a problem hiding this comment.
🎨 Would it be worth also validating the value that was passed to the facade here (and the other set methods in this file)?

🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-34009
📔 Objective
This consolidates logic that was spread between
BitwardenShared.KeychainRepository,AuthenticatorShared.KeychainRepository, andAuthenticatorBridgeKit.KeychainStorageinto oneKeychainServiceFacadeobject, and updates theKeychainRepositoryobjects accordingly. In the process, I also tried to write new tests in Swift Testing, and convert a lot of our bespoke mock objects into AutoMockable, and therefore also needed to update tests.This effectively updates the architecture from this:
flowchart TD BSKRAT[getAccessToken] BSKRNL[getNeverLock] BSKRG[getValue] subgraph BitwardenShared.KeychainRepository direction TD BSKRAT-->BSKRG BSKRNL-->BSKRG end ASKRSK[getSecretKey] ASKRUAK[getUserAccessKey] ASKRG[getValue] subgraph AuthenticatorShared.KeychainRepository direction TD ASKRSK-->ASKRG ASKRUAK-->ASKRG end subgraph AuthenticatorBridgeKit.KeychainRepository direction TD ABKAK[getAuthenticatorKey] ABKALT[getAutoLogoutTime] end subgraph AuthenticatorBridgeKit.KeychainStorage ABKG[getValue] ABKAK-->ABKG ABKALT-->ABKG end subgraph BitwardenKit.KeychainService BKKSS[search] BSKRG-->BKKSS ASKRG-->BKKSS ABKG-->BKKSS endTo this:
flowchart TD subgraph BitwardenShared.KeychainRepository direction TD BSKRAT[getAccessToken] BSKRNL[getNeverLock] end subgraph AuthenticatorShared.KeychainRepository direction TD ASKRSK[getSecretKey] ASKRUAK[getUserAccessKey] end subgraph AuthenticatorBridgeKit.KeychainRepository direction TD ABKAK[getAuthenticatorKey] ABKALT[getAutoLogoutTime] end subgraph BitwardenKit.KeychainServiceFacade BKKSWG[getValue] BSKRAT-->BKKSWG BSKRNL-->BKKSWG ASKRSK-->BKKSWG ASKRUAK-->BKKSWG ABKAK-->BKKSWG ABKALT-->BKKSWG end subgraph BitwardenKit.KeychainService BKKSS[search] BKKSWG-->BKKSS end†diagrams are just for some getters; set and delete and other properties all work similarly from an architectural perspective